package com.cskaoyan.config5;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.Data;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import com.cskaoyan.config5.DataSourceProperties5;

/**
 * @author stone
 * @date 2022/09/05 14:47
 */
@Configuration
@Data //提供set方法
@EnableConfigurationProperties(DataSourceProperties5.class)//通过该注解完成的组件注册
public class DatasourceConfiguration5 {

    /*@Autowired
    DataSourceProperties properties;*/

    DataSourceProperties5 properties;

    public DatasourceConfiguration5(DataSourceProperties5 properties) {
        this.properties = properties;
    }

    @Bean
    public DataSource dataSource5() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(properties.getDriverClass());
        dataSource.setUrl(properties.getUrl());
        dataSource.setUsername(properties.getUsername());
        dataSource.setPassword(properties.getPassword());
        return dataSource;
    }
}
